<!-- 新增/编辑指标 -->
<template>
  <a-drawer
    width="45%"
    :visible="drawerVisible"
    @ok="handleOk"
    @cancel="handleCancel"
    draggable
    title-align="center"
    unmountOnClose
  >
    <template #title> 设置方案最低分 </template>
    <div>
      <a-form ref="refForm" :rules="rules" auto-label-width>
        <a-form-item label="最低分数" field="upperLimitScore" show-colon>
          <a-input-number
            :style="{ width: '320px' }"
            placeholder="最低分数"
            allow-clear
            v-model="minScore"
            hide-button
          >
          </a-input-number>
        </a-form-item>
      </a-form>
    </div>
    <template #footer>
      <a-space>
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" @click="handleOk">确认</a-button>
      </a-space>
    </template>
  </a-drawer>
</template>

<script lang="ts" setup>
import { cloneDeep } from 'lodash';
import { PerformanceAssessmentTemplateDimensionality } from '@/apis/management/performance/baseSetting/template/type';
import type { ProbationExamine } from '@/apis/human/base/variationManager/probation/type';
import { useVModel } from '@vueuse/core';

const props = withDefaults(
  defineProps<{
    visible: boolean; // 是否显示对话框
    minScore: number; // 传进来的数据,
  }>(),
  {}
);

const emits = defineEmits([
  'update:visible',
  'update:minScore',
  'minScoreChange'
]);
const minScore = ref<number>();
const drawerVisible = useVModel(props, 'visible', emits);
const modelValue = useVModel(props, 'minScore', emits);

let refForm = ref();

const rules = reactive({
  minScore: [
    {
      required: true,
      message: '请选择'
    }
  ]
});

watch(
  () => props.visible,
  (newVal: boolean) => {
    minScore.value = cloneDeep(props.minScore);
  }
);

const handleOk = async () => {
  if (await refForm.value.validate()) {
    return;
  }
  console.log('minScore.value', minScore.value);

  modelValue.value = minScore.value;
  drawerVisible.value = false;
  emits('minScoreChange');
};

const handleCancel = () => {
  drawerVisible.value = false;
};
</script>

<style scoped lang="less">
.icon {
  cursor: pointer;
  font-size: 20px;
}
</style>
